/*
 * VariableDeclAst.cpp
 *
 *  Created on: 5 Nov 2010
 *      Author: kn308
 */

#include "VariableDeclAst.h"
#include "IntegerLiteralAst.h"

namespace MAlice
{

VariableDeclAst::VariableDeclAst(const string& name, TypeAst* type) :
	mName(name), mType(type)
{
}

VariableDeclAst::~VariableDeclAst()
{
}

llvm::Value* VariableDeclAst::generate()
{
	static Value* ONE = (new IntegerLiteralAst(1))->generate();

	Codegen* g = Codegen::get();
	Builder* builder = g->getBuilder();
	Value* value = builder->CreateAlloca(mType->type(), ONE, Twine(mName));
	g->pushVar(mName, value);
	return value;
}

}
